#! /usr/bin/python

import math

def isPrime(n):
    if n == 2 or n==3 or n == 5 or n==7: return True
    if n%2 == 0 or n%3==0 or n==1: return False
    i = 5
    while (i < math.floor(math.sqrt(n))):
	  if n%i == 0 or n%(i+2)==0: return False
          i +=6
    return True

primes = []

i=2001
while (i<4000):
      if isPrime(i): primes.append(i)
      i +=2
print len(primes)

#print isPrime(60)

def sameDigits(a, b):
    return sorted(str(a)) == sorted(str(b))

minimal = 10000000
maxN = 1
maxP = 1
for i in primes:
    for j in primes:
        n = i*j
        if n > 10000000: break
        p = (i-1)*(j-1)
        ratio = float(n)/p
        #print ratio
        if ratio < minimal and sameDigits(n, p): 
           maxN = n
           maxP = p
           minimal = ratio
print i, j, maxN, maxP, minimal           


